//
//  TeamDetailInfoTalbeViewCell.m
//  NBAPro
//
//  Created by 李广松 on 16/7/11.
//  Copyright © 2016年 WYH. All rights reserved.
//

#import "TeamDetailInfoTalbeViewCell.h"


@implementation TeamDetailInfoTalbeViewCell

@synthesize headView, nameLab, positionAndNumberLab, headImgView;

- (id)initWithAge:(NSString *)age AndHeight:(NSString *)height AndWeight:(NSString *)weight AndPTS:(NSString *)pts AndREB:(NSString *)reb AndAST:(NSString *)ast AndMIN:(NSString *)min AndGP:(NSString *)gp {
    
    self = [super init];
    
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:246/255.0 green:245/255.0 blue:247/255.0 alpha:1];

        
        headView = [self createImgViewWithFrame:CGRectMake(5, 73 / 2 - 21, 42, 42)];
        [self addSubview:headView];
        
        nameLab = [CreateControl createLabelWithFrame:CGRectMake(headView.frame.origin.x + headView.frame.size.width + 5, 73 / 2 - 14, 130, 14) AndText:@"" AndTextColor:[UIColor colorWithRed:161/255.0 green:160/255.0 blue:164/255.0 alpha:1] AndBackgroundColor:[UIColor clearColor] AndTextFont:13];
        nameLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:nameLab];
        
        positionAndNumberLab = [CreateControl createLabelWithFrame:CGRectMake(nameLab.frame.origin.x, 73 / 2 + 1, 115, 14) AndText:@"" AndTextColor:nameLab.textColor AndBackgroundColor:[UIColor clearColor] AndTextFont:13];
        positionAndNumberLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:positionAndNumberLab];
        
        UIView *topView = [self createRightTopViewWithFrame:CGRectMake(positionAndNumberLab.frame.origin.x + positionAndNumberLab.frame.size.width, 73 / 2 - 12, self.frame.size.width - positionAndNumberLab.frame.origin.x + positionAndNumberLab.frame.size.width, 11) AndAge:age AndHeight:height AndWeight:weight];
        [self addSubview:topView];
        
        UIView *downView = [self createRightDownViewWithFrame:CGRectMake(positionAndNumberLab.frame.origin.x + positionAndNumberLab.frame.size.width, 73 / 2, topView.frame.size.width, 14) AndPTS:pts AndREB:reb AndAST:ast AndMIN:min AndGP:gp];
        [self addSubview:downView];
        
    }
    
    return self;
}

- (UIView *)createRightDownViewWithFrame:(CGRect)frame AndPTS:(NSString *)pts AndREB:(NSString *)reb AndAST:(NSString *)ast AndMIN:(NSString *)min AndGP:(NSString *)gp {
    
    UIView *view = [[UIView alloc] initWithFrame:frame];
    UIView *ptsView = [self createDownLabelViewWithPoint:CGPointMake(0, 0) AndName:@"PTS" AndInfo:[self changeDecimalPointWithStr:pts]];
    [view addSubview:ptsView];
    
    
    UIView *rebView = [self createDownLabelViewWithPoint:CGPointMake(ptsView.frame.origin.x + ptsView.frame.size.width + 10, 0) AndName:@"REB" AndInfo:[self changeDecimalPointWithStr:reb]];
    [view addSubview:rebView];
    
    UIView *astView = [self createDownLabelViewWithPoint:CGPointMake(rebView.frame.origin.x + rebView.frame.size.width + 10, 0) AndName:@"AST" AndInfo:[self changeDecimalPointWithStr:ast]];
    [view addSubview:astView];
    
    UIView *minView = [self createDownLabelViewWithPoint:CGPointMake(astView.frame.origin.x + astView.frame.size.width + 10, 0) AndName:@"MIN" AndInfo:[self changeDecimalPointWithStr:min]];
    [view addSubview:minView];
    
    UIView *gpView = [self createDownLabelViewWithPoint:CGPointMake(minView.frame.origin.x + minView.frame.size.width + 10, 0) AndName:@"GP" AndInfo:[self changeDecimalPointWithStr:gp]];
    [view addSubview:gpView];
    
    return view;
}

- (NSString *)changeDecimalPointWithStr:(NSString *)string {
    float strFlo = [string floatValue];
    
    string = [[NSString alloc] initWithFormat:@"%.1f", strFlo];
    
    return string;
    
}


- (UIView *)createRightTopViewWithFrame:(CGRect)frame AndAge:(NSString *)age AndHeight:(NSString *)height AndWeight:(NSString *)weight{
    
    UIView *view = [[UIView alloc] initWithFrame:frame];
    
    UIView *ageView = [self createTopLabelViewWithPoint:CGPointMake(0, 0) AndName:@"Age" AndInfo:age];
    [view addSubview:ageView];
    
    UIView *heightView = [self createTopLabelViewWithPoint:CGPointMake(ageView.frame.origin.x + ageView.frame.size.width + 17, 0) AndName:@"Height" AndInfo:height];
    [view addSubview:heightView];
    
    UIView *weightView = [self createTopLabelViewWithPoint:CGPointMake(heightView.frame.origin.x + heightView.frame.size.width + 17, 0) AndName:@"Weight" AndInfo:weight];
    [view addSubview:weightView];

    
    return view;
}

- (UIView *)createDownLabelViewWithPoint:(CGPoint)point AndName:(NSString *)name AndInfo:(NSString *)info {
   
    UILabel *infoLabel = [CreateControl createLabelWithFrame:CGRectMake(0, 0, [self getSizeWithString:info AndFont:12].width, 13) AndText:info AndTextColor:[UIColor colorWithRed:118/255.0 green:129/255.0 blue:150/255.0 alpha:1] AndBackgroundColor:[UIColor clearColor] AndTextFont:12];
    
    UILabel *nameLabel = [CreateControl createLabelWithFrame:CGRectMake(infoLabel.frame.origin.x + infoLabel.frame.size.width, 2, [self getSizeWithString:name AndFont:10].width, 11) AndText:name AndTextColor:[UIColor colorWithRed:181/255.0 green:188/255.0 blue:203/255.0 alpha:1] AndBackgroundColor:[UIColor clearColor] AndTextFont:10];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(point.x, point.y, infoLabel.frame.size.width + nameLabel.frame.size.width, 11)];
    [view addSubview:nameLabel];
    [view addSubview:infoLabel];
    
    return view;
    
}

- (UIView *)createTopLabelViewWithPoint:(CGPoint)point AndName:(NSString *)name AndInfo:(NSString *)info {
    NSString *nameStr = [[NSString alloc] initWithFormat:@"%@: ", name];
    UILabel *nameLababel = [CreateControl createLabelWithFrame:CGRectMake(0, 0, [self getSizeWithString:nameStr AndFont:10].width, 11) AndText:nameStr AndTextColor:[UIColor colorWithRed:181/255.0 green:188/255.0 blue:203/255.0 alpha:1] AndBackgroundColor:[UIColor clearColor] AndTextFont:10];
    
    UILabel *infoLab = [CreateControl createLabelWithFrame:CGRectMake(nameLababel.frame.origin.x + nameLababel.frame.size.width, 0, [self getSizeWithString:info AndFont:10].width, 11) AndText:info AndTextColor:nameLababel.textColor AndBackgroundColor:[UIColor clearColor] AndTextFont:10];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(point.x, point.y, infoLab.frame.size.width + nameLababel.frame.size.width, 11)];
    [view addSubview:nameLababel];
    [view addSubview:infoLab];
    
    
    return view;
}

- (UIImageView *)createImgViewWithFrame:(CGRect)frame {
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame];
    imgView.layer.cornerRadius = imgView.frame.size.width / 2;
    imgView.layer.borderWidth = 1;
    imgView.layer.borderColor = [UIColor yellowColor].CGColor;
    imgView.layer.masksToBounds = YES;
    
    headImgView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, frame.size.width + 10, frame.size.height)];
    [imgView addSubview:headImgView];
    
    return imgView;
}

- (CGSize)getSizeWithString:(NSString *)string AndFont:(float)font {
    CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
    
    return size;
}




@end
